/*
 * @Author: cmd 
 * @wechat: cmd_develop 
 * @Date: 2019-04-15 10:32:30 
 * @Last Modified by: cmd 
 * @Last Modified time: 2019-04-15 10:32:30 
 * @Description: 屏幕适配，以宽为标注，高做相应的拉伸(竖屏) 750/1334 = 0.5625
 */

import orc from "../../../orc";
const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
    //LIFE-CYCLE CALLBACKS:

    onLoad () {        
        if(orc.memory_data.orc_config.widget_scale == 0 || orc.memory_data.orc_config.widget_scale == undefined)
        {
            let frameSize=cc.view.getFrameSize();  
            
            if(frameSize.height > frameSize.width)
            {
                /*竖屏游戏*/
                //算出需要拉伸多少，同时只保留1为有效数
                cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
                orc.memory_data.orc_config.widget_scale = Number((frameSize.height * 0.5625 / frameSize.width).toFixed(2));
                console.log("开始拉伸Y");
                cc.find("Canvas").getChildByName('auto_bg').scaleY = Number(orc.memory_data.orc_config.widget_scale);
            }
            else
            {
                /*横屏游戏*/
                cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
                orc.memory_data.orc_config.widget_scale = Number((frameSize.width * 0.5625 / frameSize.height).toFixed(2));
                console.log("开始拉伸X");
                cc.find("Canvas").getChildByName('auto_bg').scaleX = Number(orc.memory_data.orc_config.widget_scale);
            }            
            console.log("计算需要拉伸：",orc.memory_data.orc_config.widget_scale);            
        }
        
        //cc.find("Canvas/auto_bg").scaleY = Number(orc.memory_data.orc_config.widget_scaleY);
    }

    start () {

    }

    // update (dt) {}
}
